<template>
	<view class="subsidy">
		<view class="subsidyHead" :style="{height : headHeight}">
			<view class="subsidyHead-txt" :style="{marginTop: headMarginTaop}">
				补助金管理
			</view>
		</view>
		<view class="subsidy-nav">
			<view class="subsidy-nav-box" @click="cli_nav(item, index)" v-for="(item, index) of list_nav" :key="index">
				<text :class="index_nav == index?'subsidy-nav-box-txt' : ''">{{item.name}}</text>
				<text v-if="index_nav == index" class="subsidy-nav-box-btm"></text>
			</view>
		</view>
		<view v-if="list && list.length >0" class="subsidy-list">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
				@scrolltolower="lower">
				<view class="subsidy-li" @click="cli_goDetails(item, index)" v-for="(item, index) of list" :key="index">
					<view class="subsidy-li-head">
						<text class="subsidy-li-head-txt1">{{item.createTime}}</text>
						<text class="subsidy-li-head-txt2 font_blod" :class="[item.applyStatus == 0 || item.applyStatus == 1 || item.applyStatus == 3? 'subsidy-li-head-txt2-3' : '',item.applyStatus == 5? 'subsidy-li-head-txt2-2' : '']">{{changeapplyStatus(item.applyStatus)}}</text>
					</view>
					<view class="subsidy-li-main">
						<view class="subsidy-li-main-left">
							<view class="subsidy-li-boxli">
								<text class="subsidy-li-boxli-left">配件名称</text>
								<text class="subsidy-li-boxli-right font_blod">{{item.attributeName}}</text>
							</view>
							<view class="subsidy-li-boxli">
								<text class="subsidy-li-boxli-left">申请补助金金额</text>
								<text class="subsidy-li-boxli-right font_blod">￥{{item.payPrice}}</text>
							</view>
							<view class="subsidy-li-boxli">
								<text class="subsidy-li-boxli-left">维修师傅</text>
								<text class="subsidy-li-boxli-right font_blod">{{item.storeName}}</text>
							</view>
							<view class="subsidy-li-boxli">
								<text class="subsidy-li-boxli-left">故障描述</text>
								<text class="subsidy-li-boxli-right font_blod">{{item.faultDetails}}</text>
							</view>
							<view class="subsidy-li-boxli" v-if="item.applyStatus == 1 || item.applyStatus == 2 || item.applyStatus == 3 || item.applyStatus == 4 ">
								<text class="subsidy-li-boxli-left">鉴定结果</text>
								<text class="subsidy-li-boxli-right font_blod subsidy-li-boxli-right-jieguo">{{changeapplyStatus2(item.applyStatus)}}</text>
							</view>
						</view>
						<!-- <view class="subsidy-li-main-right">
							<image v-if="item.applyStatus == 5 || item.applyStatus == 6 || item.applyStatus == 7" class="subsidy-li-main-right-img"
								src="../../../static/manufacturers/yitongguo.png" mode=""></image>
							<image  v-if="item.applyStatus == 2 || item.applyStatus == 4" class="subsidy-li-main-right-img" src="../../../static/manufacturers/yibohui.png"
								mode=""></image>
						</view> -->
					</view>

				</view>
			</scroll-view>
		</view>
		<view v-else class="subsidy-list">
			<view class="yPopNone">
				<image class="yPopNoneImg" src="https://www.zzzsyh.com/applets/agent/factory/23.png" mode=""></image>
				<view class="yPopNoneTxt">
					暂无补助金~
				</view>
			</view>
		</view>
		<!-- 底部导航 -->
		<view class="tabbarBox">
			<view class="tabbarBox-li" @click="cli_go_order">
				<image class="tabbarBox-li-img" src="../../../static/manufacturers/tab1_2.png" mode=""></image>
				<text class="tabbarBox-li-txt font_blod">
					订单管理
				</text>
			</view>
			<view class="tabbarBox-li">
				<image class="tabbarBox-li-img" src="../../../static/manufacturers/tab2_2.png" mode=""></image>
				<text class="tabbarBox-li-txt font_blod">
					补助金
				</text>
			</view>
			<view class="tabbarBox-li" @click="cli_go_mycenter">
				<image class="tabbarBox-li-img" src="../../../static/manufacturers/tab3.png" mode=""></image>
				<text class="tabbarBox-li-txt font_blod">
					我的
				</text>
			</view>
		</view>
	</view>
</template>

<script>
	import allapi from '../api/index.js'
	export default {
		data() {
			return {
				factoryId: uni.getStorageSync('factoryId'),
				headHeight: '',
				headMarginTaop: '',
				list_nav: [{name: '全部',state: ''},{name: '处理中',state: '1'},{name: '已审核',state: '5'},{name: '已赔付',state: '7'}],
				index_nav: 0,
				scrollTop: 0,
				pageNum: 1,
				status: '',
				showMore: true,
				list: []
			}
		},
		onShow() {
			// 获取列表啊
			// this.getQrCodeApplyListByFactoryId()
			this.pageInit()
		},
		mounted() {
			this.getHeight()
		},
		methods: {
			upper: function(e) {
				console.log(e)
				this.pageInit()
			},
			lower: function(e) {
				console.log(e)
				if (this.showMore) {
					this.pageNum += 1
					this.getQrCodeApplyListByFactoryId()
				} else {
					this.showMore = false
				}
			},
			// 切换导航
			cli_nav(item, index) {
				console.log(item, index);
				this.index_nav = index
				this.status = item.state
				this.pageInit()
			},
			// 跳转详情
			cli_goDetails(item, index) {
				uni.navigateTo({
					url: '/pages/manufacturers/subsidyDetail/subsidyDetail?id=' + item.id
				})
			},
			// 跳转订单管理
			cli_go_order() {
				uni.redirectTo({
					url: '/pages/manufacturers/order/order'
				})
			},
			// 跳转我的
			cli_go_mycenter() {
				uni.redirectTo({
					url: '/pages/manufacturers/mycenter/mycenter'
				})
			},
			// 初始化
			pageInit() {
				this.showMore = true
				this.pageNum = 1
				this.list = []
				this.getQrCodeApplyListByFactoryId()
			},
			// 获取列表
			getQrCodeApplyListByFactoryId() {
				uni.request({
					url: allapi.getQrCodeApplyListByFactoryId,
					data: {
						factoryId: this.factoryId,
						pageNum: this.pageNum,
						pageSize: 10,
						status: this.status,
					},
					success: (res) => {
						console.log('获取列表', res);
						let dat = res.data.data
						if (dat && dat.length > 0) {
							this.list = this.list.concat(dat)
							this.showMore = true
						} else {
							this.showMore = false
						}
					},
					fail: (err) => {
						console.log(err);
					}
				})
			},
			// 获取系统信息
			getHeight() {
				let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
				let h = menuButtonInfo.bottom + 6 + 'px'
				let m = menuButtonInfo.top + 'px'
				this.headHeight = h
				this.headMarginTaop = m
			},
			changeapplyStatus (val) {
				if (val == 0 ) {
					return '待处理'
				}else if(val == 1 || val == 3) {
					return '处理中'
				}else if (val == 2 || val == 4) {
					return '已驳回'
				}else if (val == 5) {
					return '已审核'
				}else if (val == 6 || val == 7) {
					return '已赔付'
				}
			},
			changeapplyStatus2 (val) {
				if (val == 0 ) {
					return '待处理'
				}else if(val == 1) {
					return '市县已鉴定'
				}else if(val == 2) {
					return '市县已驳回'
				}else if(val == 3) {
					return '大区已鉴定'
				}else if (val == 4) {
					return '大区已驳回'
				}else if (val == 5) {
					return '平台已审核'
				}else if (val == 6) {
					return '已赔付'
				}else if (val == 7) {
					return '已赔付'
				}
			}
		}
	}
</script>

<style scoped>
	.subsidy {
		position: absolute;
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		left: 0;
		top: 0;
	}

	.subsidyHead {
		background: linear-gradient(270deg, #3CC5EF 0%, #74DFC5 100%);
		padding-top: 0.1rpx;
	}

	.subsidyHead-txt {
		line-height: 32px;
		font-size: 36rpx;
		color: #FFFFFF;
		margin-left: 80rpx;
	}

	.subsidy-nav {
		height: 88rpx;
		display: flex;
		justify-content: space-around;
		background: #FFFFFF;
	}

	.subsidy-nav-box {
		font-size: 28rpx;
		color: #666666;
		line-height: 80rpx;
		display: flex;
		flex-direction: column;
		/* justify-content: center; */
		align-items: center;
	}
	.subsidy-nav-box-txt {
		color: #5DD4D6;
		font-weight: bold;
	}
	.subsidy-nav-box-btm {
		width: 64rpx;
		height: 8rpx;
		border-radius: 4rpx;
		display: block;
		background: linear-gradient(to right, #3CC5EF, #74DFC5);
	}

	.subsidy-list {
		flex: 1;
		margin: 0 24rpx;
		overflow: hidden;
	}

	.scroll-Y {
		height: 100%;
	}

	.tabbarBox {
		left: 0;
		bottom: 0;
		/* position: fixed; */
		width: 100%;
		height: 120rpx;
		background: #FFFFFF;
		display: flex;
		justify-content: space-around;
		align-items: center;
		box-shadow: 0px -4px 8px 0px rgba(0, 0, 0, 0.1);
		padding-bottom: env(safe-area-inset-bottom);
	}

	.tabbarBox-li {
		width: 200rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.tabbarBox-li-img {
		width: 60rpx;
		height: 60rpx;
	}

	.tabbarBox-li-txt {
		font-size: 24rpx;
		color: #666666;
	}

	.subsidy-li {
		background: #FFFFFF;
		border-radius: 16rpx;
		padding: 24rpx;
		margin-top: 24rpx;
	}

	.subsidy-li-head {
		border-bottom: 1rpx solid #EEEEEE;
		height: 54rpx;
		/* line-height: 54rpx; */
	}

	.subsidy-li-head-txt1 {
		font-size: 24rpx;
		color: #999999;
	}

	.subsidy-li-head-txt2 {
		font-size: 28rpx;
		color: #999999;
		float: right;
	}

	.subsidy-li-head-txt2-2 {
		color: #42C8EA;
	}
	.subsidy-li-head-txt2-3 {
		color: #72DEC6;
	}

	.subsidy-li-boxli {
		display: flex;
		align-items: center;
		margin-top: 20rpx;
	}

	.subsidy-li-boxli-left {
		width: 192rpx;
		font-size: 28rpx;
		color: #666666;
	}

	.subsidy-li-boxli-right {
		flex: 1;
		font-size: 28rpx;
		color: #333333;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	.subsidy-li-boxli-right-jieguo {
		color: #E98703;
	}
	.subsidy-li-main {
		display: flex;
		align-items: center;
	}

	.subsidy-li-main-left {
		flex: 1;
		overflow: hidden;
	}

	.subsidy-li-main-right {
		margin-right: -24rpx;
		width: 152rpx;
	}

	.subsidy-li-main-right-img {
		width: 152rpx;
		height: 152rpx;
	}
</style>
